package com.itheima.college_infomaneger_sys.service;

import com.itheima.college_infomaneger_sys.dao.StudentDao;
import com.itheima.college_infomaneger_sys.domain.Student;

public class StudentService {
    private static StudentDao dao = new StudentDao();
    private static Student[] stus = dao.getAllStudents();

    public static boolean addStudent(Student stu) {
        return dao.addStudent(stu);
    }

    public boolean isExist(String id) {
        for (int i = 0; i < stus.length; i++) {
            Student stu = stus[i];
            if (stu != null && stu.getId().equals(id)) {
                return true;
            }
        }
        return false;
    }

    public boolean isEmpty() {
        for (int i = 0; i < stus.length; i++) {
            Student stu = stus[i];
            if (stu != null) {
                return false;
            }
        }
        return true;
    }

    public void getAllStudents() {
        if (isEmpty()){
            System.out.println("不存在学生信息!");
            return;
        }
        System.out.println("学号\t\t姓名\t\t年龄\t\t出生日期");
        for (int i = 0; i < stus.length; i++) {
            Student stu = stus[i];
            if (stu != null) {
                System.out.println(stu.getId() + "\t" + stu.getName() + "\t\t" + stu.getAge() + "\t\t" + stu.getBirthday());
            }
        }
    }

    public void delStudentInfo(String id) {
        int existId = dao.getExistId(id);
        dao.delStudentInfo(existId);


    }
}
